const KoaRouter = require('koa-router')

class Router {
    constructor() {     
        this.$router = new KoaRouter();
    }

    /**
     * 生成资源路由
     * 
     * @param {any} name 
     * @param {any} controller 
     * @memberof Api
     */
    async resource (name, controller) {
        this.$router.get(`/${name}`, controller.index)
        this.$router.get(`/${name}/create`,  controller.create)
        this.$router.post(`/${name}`,  controller.store)
        this.$router.get(`/${name}/:id`,  controller.show)
        this.$router.get(`/${name}/:id/edit`,  controller.edit)
        this.$router.post(`/${name}/:id`,  controller.save)
        this.$router.get(`/${name}/:id/destroy`,  controller.destroy)
    }
}

module.exports = new Router()